<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit"/>
    <title>电脑商城</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="../css/layout.css"/>
    <link rel="stylesheet" type="text/css" href="../css/top.css"/>
    <link rel="stylesheet" type="text/css" href="../css/footer.css"/>
</head>

<body>
<!--头部-->
<header class="header">
    <!--电脑商城logo-->
    <div class="row">
        <div class="col-md-3">
            <a href="index_admin.html">
                <img src="../images/index/stumalllogo.png"/>
            </a>
        </div>
    </div>
</header>

<div class="container">
    <div class="col-md-2">
    </div>
    <div class="col-md-10  ">
        <div class="panel panel-default">
            <div class="panel-body">
                <!--修改资料表单开始-->
                <form id="form-change-info" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-md-2 control-label"> 用户id：</label>
                        <div class="col-md-8">
                            <tr>
                                <input id="uid" name="uid" type="text" class="form-control" placeholder="uid">
                                <input id="btn-check" type="button" class="form-control" value="确定"/>
                            </tr>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">用户名：</label>
                        <div class="col-md-8">
                            <input id="username" name="username" type="text" class="form-control" value="123"
                                   readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">用户余额：</label>
                        <div class="col-md-8">
                            <input id="purse" name="purse" type="text" class="form-control" value="0"
                                   readonly="readonly">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-2 control-label">充值金额：</label>
                        <div class="col-md-8">
                            <input id="addAmount" name="addAmount" type="text" class="form-control"
                                   placeholder="请输入充值金额"
                                   value="0">
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <input id="btn-change-info" type="button" class="btn btn-primary" value="充值"/>
                            <label class="col-md-2 control-label"><a
                                    href="index_admin.html">返回</a>&nbsp;&nbsp;&nbsp;</label>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    $(document).ready(function () {
        showPurse();
    })

    $("#btn-change-info").click(function () {
        $.ajax({
            url: "/user/adminAddMoney",
            type: "POST",
            data: "uid=" + $("#uid").val() + "&addAmount=" + $("#addAmount").val(),
            dataType: "JSON",
            success: function (json) {
                if (json.state == 200) {
                    alert("充值成功");
                    showAfterPurse();
                    console.log("1:充值后" + $("#form-change-info").serialize());
                } else {
                    alert("充值失败");
                }
            },
            error: function (xhr) {
                alert("用户信息修改时产生未知的异常" + xhr.message);//自动产生错误描述信息
            }
        })
    })

    $("#btn-check").click(
        function showPurse() {
            $.ajax({
                url: "/user/get_aMoney",
                type: "GET",
                data: $("#uid").serialize(),
                dataType: "JSON",
                success: function (json) {
                    console.log(json.data);
                    if (json.state == 200) {

                        //将查询到的数据重新设置到控件中
                        //val表示给一个元素赋值，赋值到选中的元素上（#phone  一个文本框）
                        $("#uid").val(json.data.uid);
                        $("#username").val(json.data.username);
                        $("#purse").val(json.data.purse);

                        // $("#rest").val(json.data.purse);
                        // $("#username1").val(json.data.username);
                        // // $("#add").val($("#purse").val());

                        console.log("1:" + $("#form-change-info").serialize());

                    } else {
                        alert("数据不存在");
                    }
                },
                error: function (xhr) {
                    alert("在查询用户信息时产生未知异常" + xhr.message);//自动产生错误描述信息
                }
            })
        }
    )

    function showAfterPurse() {
        $.ajax({
            url: "/user/get_aMoney",
            type: "GET",
            data: $("#uid").serialize(),
            dataType: "JSON",
            success: function (json) {
                console.log(json.data);
                if (json.state == 200) {

                    //将查询到的数据重新设置到控件中
                    //val表示给一个元素赋值，赋值到选中的元素上（#phone  一个文本框）
                    $("#uid").val(json.data.uid);
                    $("#username").val(json.data.username);
                    $("#purse").val(json.data.purse);

                    // $("#rest").val(json.data.purse);
                    // $("#username1").val(json.data.username);
                    // // $("#add").val($("#purse").val());

                    console.log("1:" + $("#form-change-info").serialize());

                } else {
                    alert("数据不存在");
                }
            },
            error: function (xhr) {
                alert("在查询用户信息时产生未知异常" + xhr.message);//自动产生错误描述信息
            }
        })
    }

</script>
</body>

</html>
